* ======================================
* --------- Import relatives -----------
* ======================================


* Parents
* =======

	use "$dta_raw\dta9\W19_0078_SLEKT.dta", clear
	bysort w19:  drop if _n > 1 // a few duplicate obs
	rename w19 idPers
	
	* Separate
	foreach n in mor far{
		preserve
		rename lnr_`n' idParent
		keep idPers idParent
		keep if idParent != ""
		tempfile parent_`n'
		save `parent_`n''
		restore		
	}

	* Append
	clear
	append using `parent_mor'
	append using `parent_far'
	sort idPers
	
	save "$dta\ImportParents.dta",replace 
	
	
	
* Siblings
* ========
	
	use "$dta_raw\dta9\W19_0078_SLEKT.dta", clear
	bysort w19:  drop if _n > 1 // a few duplicate obs
	rename w19 idPers
	
	* Separate
	foreach n in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20{
		preserve
		rename lnr_sosken_`n' idSibling
		keep idPers idSibling
		keep if idSibling != ""
		tempfile sibling`n'
		save `sibling`n''
		restore
	}
	
	* Append
	clear
	foreach n in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20{
		append using `sibling`n''
	}
	sort idPers
	
	save "$dta\ImportSiblings.dta",replace 
	
	
	
* Children
* ========

	use "$dta_raw\dta9\W19_0078_SLEKT.dta", clear
	bysort w19:  drop if _n > 1 // a few duplicate obs
	rename w19 idPers
	
	* Separate
	foreach n in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22{
		preserve
		rename lnr_barn_`n' idChild
		keep idPers idChild
		keep if idChild != ""
		tempfile child`n'
		save `child`n''
		restore
	}
	
	* Append
	clear
	foreach n in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22{
		append using `child`n''
	}
	
	save "$dta\ImportChildren.dta",replace 